# -*- coding: utf-8 -*-
# @Author: Tim Liu
# @Date: 2024-10-17
# @Last Modified by: Tim Liu
# @Last Modified time: 2024-10-17

# @Description: Conversation 
# a conversation stores user-bot session id, start time, end time, user id .

from sqlalchemy.orm import relationship, Mapped, mapped_column
from sqlalchemy import String, Boolean, Integer, ForeignKey, Text, DateTime
from datetime import datetime

from db.db_base import BaseModel

from apps.vadmin.auth.models import VadminUser

class ConversationDB(BaseModel):
    __tablename__ = "crewplus_conversation"
    __table_args__ = ({'comment': 'conversations'})

    session_id: Mapped[str] = mapped_column(String(255), nullable=False, comment="conversation uuid for message separation")
    
    # conversation time, filled while begin/end
    converse_start_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, comment="conversation start time")
    converse_end_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, comment="conversation end time")

    # admin user id of x-api-key
    create_user_id: Mapped[int] = mapped_column(
        Integer,
        ForeignKey("vadmin_auth_user.id", ondelete='RESTRICT'),
        comment="create user id"
    )
    create_user: Mapped[VadminUser] = relationship(foreign_keys=create_user_id)
